package com.itheima.mycollection;

import java.util.ArrayList;
import java.util.Iterator;

public class TestStudent {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("张三",23);
        Student s2 = new Student("李四",24);
        Student s3 = new Student("王五",25);

        list.add(s1);
        list.add(s2);
        list.add(s3);

        // 迭代器的方式遍历集合
        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()){
            Student s = iterator.next();
            System.out.println(s);
        }

        System.out.println("-------------------");

        // 增强for的方式遍历集合
        for (Student student : list) {
            System.out.println(student);
        }

        System.out.println("-------------------");

        // 普通for循环的方式遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student);
        }
    }
}
